import numpy as np
import matplotlib.pyplot as plt

temperature_str = np.loadtxt('ug_detect.csv',
                             dtype=bytes,
                             delimiter=',',
                             skiprows=1,
                             usecols=(1),
                             unpack=False)

#print("读取出在数组是temperature_str: \n",temperature_str)

temperature = np.ndarray(len(temperature_str))
for index in  range(0,len(temperature_str)):
    itme = temperature_str[index]
    if itme !=b'':
        itme = itme.decode('gb2312')
        itme = float(itme)
    else:
        itme = None
    temperature[index] = itme

#print("处理后的温度数据;",temperature)
for index in range(0,len(temperature)):
    itme = temperature[index]
    if itme>= 50.0:
        itme =  None
    temperature[index] = itme

print("处理后的温度数据;",temperature)

t = np.arange(len(temperature))
#plt.plot(t,temperature)
#plt.plot(t,temperature,'pr')
#plt.show()

def bisec(dataArray):
    for index in range(0,len(dataArray)):
        if np.isnan(dataArray[index]):
            if (index-1)>=0 and (index+1)<len(dataArray):
                dataArray[index] = (dataArray[index-1] + dataArray[index + 1])*0.5
bisec((temperature))
t = np.arange(len(temperature))
plt.plot(t,temperature)
plt.plot(t,temperature,'pr')
plt.show()

print("处理完缺失值：", temperature)

np.savetxt("ug_tem")